package com.itheima.d1_map_impl;

import java.util.TreeMap;

public class Test03TreeMapLianxi {
    public static void main(String[] args) {
        TreeMap<Student, String> students = new TreeMap<>();

        students.put(new Student("张三", 18, 185), "上海");
        students.put(new Student("李四", 15, 160), "上海");
        students.put(new Student("王五", 20, 190), "上海");
        students.put(new Student("赵六", 19, 125), "上海");

        students.forEach((k,v)-> System.out.println(k + " ---> " + v));

        System.out.println("=========");

        //年龄降序排序
        TreeMap<Student, String> students2 = new TreeMap<>((s1, s2) -> Integer.compare(s2.getAge(), s1.getAge()));
        students2.put(new Student("张三", 18, 185), "上海");
        students2.put(new Student("李四", 15, 160), "上海");
        students2.put(new Student("王五", 20, 190), "上海");
        students2.put(new Student("赵六", 19, 125), "上海");
        students2.forEach((k,v)-> System.out.println(k + " ---> " + v));
    }
}
